package com.wl.response;

import lombok.Data;

import java.io.Serializable;

/**
 * @program: treeHole
 * @author: 吴磊
 * @create: 2021-07-06 18:26
 */
@Data
public class CommonReturnType implements Serializable {
    private static final long serialVersionUID = 3384269592585772988L;
    private String code;
    private Object data;
    private String message;

    public static CommonReturnType success(Object data) {
        return CommonReturnType.create("200", data, null);
    }

    public static CommonReturnType success(String code, Object data) {
        return CommonReturnType.create(code, data, null);
    }

    public static CommonReturnType fail(String message) {
        return CommonReturnType.create("500", null, message);
    }

    public static CommonReturnType fail(String code, String message) {
        return CommonReturnType.create(code, null, message);
    }

    private static CommonReturnType create(String code, Object data, String message) {
        CommonReturnType commonReturnType = new CommonReturnType();
        commonReturnType.setCode(code);
        commonReturnType.setData(data);
        commonReturnType.setMessage(message);
        return commonReturnType;
    }
}
